import {TFontCombobox, TPanel, TToolMenuButton} from "../../hcl/StdCtrls.js";
import {TColor} from "../../hcl/Graphics.js";
import {TAlign} from "../../hcl/Controls.js";
import {EmrImageButton} from "./EmrImageButton.js";
import {EmrToolbar} from "./EmrToolbar.js";
import {TStream} from "../../hcl/System.js";
import {application} from "../../hcl/Application.js";
import {EmrToolMenuButton} from "./component/EmrToolMenuButton.js";

export class FilePanel extends TPanel{
    constructor(options={top:0,width:0,color:TColor.DarkGray,height:30}) {
        super();
        this.top = options.top;
        this.width = options.width;
        this.color =options.color;


        let toolbar = new EmrToolbar();
        toolbar.align = TAlign.Top;
        toolbar.height =70;
        toolbar.color = this.color;

        let imgBtn = new EmrImageButton("保存","../image/file.png");
        imgBtn.onClick = this.save;
        toolbar.addControl(imgBtn);

        let newVersionBtn = new EmrImageButton("新版本","../image/file.png");
        newVersionBtn.onClick = this.newVersion;
        toolbar.addControl(newVersionBtn);


        let printBtn = new EmrToolMenuButton("打印","../image/file.png",[
            "全部",
            "当前页",
            "奇数页",
            "偶数页",
            "指定页或范围",
            "当前行-当前页",
            "当前行-最后页",
            "当前页选中内容",
            "预览"
        ]);

        printBtn.onClick = this.print;
        toolbar.addControl(printBtn);

        let exportBtn = new EmrToolMenuButton("导出","../image/file.png",[
            "下载文件",
            "下载为PDF"
        ]);
        toolbar.addControl(exportBtn);

        toolbar.addSpliter();

        let dagangBtn = new EmrImageButton("大纲","../image/file.png");
        toolbar.addControl(dagangBtn);

        let aboutBtn = new EmrImageButton("关于","../image/file.png");
        toolbar.addControl(aboutBtn);

        this.addControl(toolbar);
    }

    newVersion(){

        alert("暂未实现");
    }

    print(){

    }

    save(){
        let vStream = new TStream();
        window.mainForm.hcView.SaveToStream(vStream, false);

        let vByteData = new Uint8Array(vStream.buffer);
        let vBlob = new Blob([vByteData], {type:"application/octet-stream"});
        //let vBlob = new Blob(vStream.buffer, {type:"application/octet-stream"});
        let vDownloadUrl = window.URL.createObjectURL(vBlob);
        let vAnchor = document.createElement("a");
        vAnchor.href = vDownloadUrl;
        vAnchor.download = "HCView H5.hcf";
        vAnchor.click();
        window.URL.revokeObjectURL(vBlob);
    }
}